<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .active {
            background: red;
        }
    </style>
</head>
<body>
    <button>点我</button>
    <button>点我</button>
    <button>点我</button>
    <button>点我</button>
    <button>点我</button>

    <script>

        const btns = document.querySelectorAll('button');

        for (const btn of btns) {
            // 按钮.添加事件
            btn.addEventListener('click', function () {
                // 点击时要干的事
                // 1. 干掉所有人
                for (const btn of btns) {
                    btn.setAttribute('class', '');
                }
                // 2. 复活自己(this)
                this.setAttribute('class', 'active');
            });
        }


    </script>
</body>
</html>